// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
#[tauri::command]
fn greet(name: &str) -> String {
    format!("Hello, {}! You've been greeted from Rust!", name)
}

mod migration;

#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
    //获取主目录
    let home_path = model_graph_common::utils::rrg01_home_path().expect("获取程序目录失败!");

    tracing::info!(
        "程序启动主目录:{}",
        format!("{}", home_path.to_str().expect("获取程序目录失败!")).as_str()
    );

    tauri::Builder::default()
        .plugin(
            tauri_plugin_sql::Builder::default()
                .add_migrations(
                    format!(
                        "sqlite:{}/rrg01.sqlite",
                        home_path.to_str().expect("获取程序目录失败!")
                    )
                    .as_str(),
                    crate::migration::migrations(),
                )
                .build(),
        )
        .plugin(tauri_plugin_shell::init())
        .plugin(tauri_plugin_process::init())
        .plugin(tauri_plugin_clipboard_manager::init())
        .plugin(tauri_plugin_os::init())
        .plugin(tauri_plugin_dialog::init())
        .plugin(tauri_plugin_fs::init())
        .plugin(tauri_plugin_shell::init())
        .plugin(tauri_plugin_http::init())
        .plugin(tauri_plugin_mg_platform::init())
        .plugin(tauri_plugin_mg_connector::init())
        .invoke_handler(tauri::generate_handler![greet])
        .setup(|app| {
            #[cfg(desktop)]
            app.handle()
                .plugin(tauri_plugin_updater::Builder::new().build())?;
            Ok(())
        })
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}
